<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>copy</title>
		<script src="js/vconsole.min.js">
		</script>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<style>
			body {
			  display: flex;
			  align-items: center;
			  justify-content: center;
			  min-height: 100vh;
			  background: #efefef;
			}
			input {
			  font-size: 1rem;
			  padding: 0.5rem;
			}
		</style>
		
	</head>
	<body>
		<input
		  id = "codeID"
		  type="text"
		/>
		<script type="text/javascript">
		new VConsole();
	
		
	// let strq =""
	// //PC端可以监听paste
	//  window.addEventListener("paste",  (e) => {
	// 					      const clipdata = e.clipboardData || window.clipboardData;
	// 						  strq = clipdata.getData("text/plain")
	// 						 setTimeout( () => {
	// 							 let codeID = document.getElementById("codeID");
	// 							 console.log("===2===",strq)
	// 							 console.log("===3===",strq.slice(1,2))
	// 							 codeID.value = strq.slice(1,2);
	// 						 },100);
							
	// 				});
					
					
					
				
	//移动端监听不了paste	采取监测变化oninput 加正则取第一次出现的4位数字	
	let codeID = document.getElementById("codeID");
				console.log("===2===",codeID)
					codeID.oninput = function(e) {
						
						const styleReg = /[0-9]{4}/g;
						console.log("styleTag",styleReg)
						let str = codeID.value.slice(0,20);
						let styleTag = styleReg.exec(str); //source.match(regex);
					
						console.log("styleTag",styleTag)
						if(str.length >= 6){
							if(!styleTag){
								alert("抱歉验证码不符合4位数字")
								  codeID.value = "";
							}
						}
						
					   codeID.value = styleTag[0] || '';
					}

		</script>
	</body>
	
</html>